<template>
  <div>
    <el-tag :type="state.type" v-if="renderRow.status">{{
      state.statusDict[Number(renderRow.status)]
    }}</el-tag>
    <el-tag :type="state.type" v-else-if="renderRow.printStatus">{{
      state.statusDict[Number(renderRow.printStatus)]
    }}</el-tag>
    <el-tag :type="state.type" v-else-if="renderRow.state !== null">{{
      state.statusDict[Number(renderRow.state)]
    }}</el-tag>
    <el-tag :type="state.type" v-else-if="renderRow.planState !== null">{{
      state.statusDict[renderRow.planState]
    }}</el-tag>
    <el-tag :type="state.type" v-else-if="renderRow.processState !== null">{{
      state.statusDict[renderRow.processState]
    }}</el-tag>
    <el-tag :type="state.type" v-else>{{
      state.statusDict[Number(renderRow.orderStatus)]
    }}</el-tag>
  </div>
</template>
<script lang="ts" setup>
import { ref, onMounted, reactive, inject } from "vue";
import type { TableColumn, TableRow, OptButton } from "@/utils/baTable"; //表格列行类型
import { CollectionTag } from "@element-plus/icons-vue";
const dictionary = inject("dictionary") as any;

// BuildAdmin将自动为此组件传递五个Props
interface Props {
  renderValue: any; // 单元格值
  renderRow: TableRow; // 当前行数据
  renderField: TableColumn; // 当前列数据
}

const props = withDefaults(defineProps<Props>(), {});

const state: { statusDict: anyObj; type: string } = reactive({
  statusDict: dictionary.tag,
  type:
    dictionary.tag[Number(props.renderRow.status)] === "在线" ||
    dictionary.tag[Number(props.renderRow.status)] === "已完成" ||
    dictionary.tag[Number(props.renderRow.status)] === "已考核" ||
    dictionary.tag[Number(props.renderRow.orderStatus)] === "已付款" ||
    dictionary.tag[Number(props.renderRow.printStatus)] === "已打印" ||
    dictionary.tag[Number(props.renderRow.state)] === "已处理" ||
    dictionary.tag[Number(props.renderRow.state)] === "已完成" ||
    dictionary.tag[props.renderRow.planState] === "已完成" ||
    dictionary.tag[props.renderRow.processState] === "已完成"
      ? "success"
      : dictionary.tag[Number(props.renderRow.status)] === "离线" ||
        dictionary.tag[Number(props.renderRow.status)] === "待接单" ||
        dictionary.tag[Number(props.renderRow.status)] === "待派单" ||
        dictionary.tag[Number(props.renderRow.orderStatus)] === "取消付款" ||
        dictionary.tag[Number(props.renderRow.printStatus)] === "未打印" ||
        dictionary.tag[Number(props.renderRow.state)] === "离线" ||
        dictionary.tag[Number(props.renderRow.state)] === "待执行" ||
        dictionary.tag[props.renderRow.planState] === "已签收" ||
        dictionary.tag[props.renderRow.processState] === "已签收"
      ? "info"
      : dictionary.tag[Number(props.renderRow.status)] === "未激活" ||
        dictionary.tag[Number(props.renderRow.status)] === "服务中" ||
        dictionary.tag[Number(props.renderRow.state)] === "未激活" ||
        dictionary.tag[Number(props.renderRow.status)] === "待执行" ||
        dictionary.tag[Number(props.renderRow.state)] === "执行中" ||
        dictionary.tag[Number(props.renderRow.planState)] === "加工中" ||
        dictionary.tag[Number(props.renderRow.processState)] === "加工中" ||
        dictionary.tag[Number(props.renderRow.orderStatus)] === "交易关闭"
      ? "warning"
      : dictionary.tag[props.renderRow.planState] === "已下达" ||
        dictionary.tag[props.renderRow.planState] === "已派工" ||
        dictionary.tag[props.renderRow.processState] === "已下达" ||
        dictionary.tag[props.renderRow.processState] === "已派工"
      ? "primary"
      : "danger",
});

onMounted(() => {
  console.log(
    "单元格值",
    props.renderRow,
    state.statusDict,
    state.statusDict[Number(props.renderRow.state)],
    state.statusDict[props.renderRow.planState]
  );
});
</script>
<style lang="scss" scoped></style>
